<?php
$content_type = array('contact'=>'联系我们','about'=>'关于我们','privacy'=>'隐私声明','wholesale'=>'批发方案');

switch($a){
    case 'post1':
        unset($_POST['a']);
        $sql = "INSERT INTO system_settings(`".implode("`,`",array_keys($_POST))."`) VALUES('".implode("','",  array_values($_POST))."')";
        if($db->query($sql)){
            make_setting_cache($_POST);
            $status = 1;
            $info = '保存成功';
        }else{
            $status = 0;
            $info = '保存失败';
        }
        echo ajax_return($status, $info);
        exit();
        break;
    case 'upadte_content':
        $type = trim($type);
        if(in_array($type,  array_keys($content_type))){
            $sql = "INSERT INTO system_settings_article(`type`,`content`,`create_time`) VALUES('{$type}','{$content}','".time()."')";
            if($db->query($sql) && php2html('index','article',array('type'=>$type),'type')){
                $status = 1;
                $info = '保存成功';
            }else{
                $status = 0;
                $info = '数据写入失败';
            }
        }else{
            $status = 0;
            $info = '错误的文章类别';
        }
        echo ajax_return($status, $info);
        exit();
        break;
    default:
        //CKeditor
        // Include the CKEditor class.
        include_once(APP_ROOT."/include/ckeditor/ckeditor.php");
        // Create a class instance.
        $CKEditor = new CKEditor();//exit("123");
        // Do not print the code directly to the browser, return it instead.
        $CKEditor->returnOutput = true;
        // Path to the CKEditor directory, ideally use an absolute path instead of a relative dir.
        //   $CKEditor->basePath = '/ckeditor/'
        // If not set, CKEditor will try to detect the correct path.
        $CKEditor->basePath = APP_URL.'/include/ckeditor/';
        // Set global configuration (will be used by all instances of CKEditor).
        $CKEditor->config['width'] = '80%';
        // Change default textarea attributes.
        $CKEditor->textareaAttributes = array("cols" => 80, "rows" => 10);

        foreach($content_type as $k => $v){
            $$k = $db->result_first("SELECT content FROM system_settings_article WHERE type='{$k}' ORDER BY id DESC LIMIT 0,1");
        }

        //站点信息
        $site = $db->fetch_first("SELECT * FROM system_settings ORDER BY id DESC LIMIT 0,1");
        break;
}
?>